<?php
// +----------------------------------------------------------------------
// | Author: yaoyihong <510974211@qq.com>
// +----------------------------------------------------------------------

namespace app\api\model;


class User extends ApiBase
{
	protected $insert  = ['create_time'];

	protected $auto = ['last_login_time','last_login_ip'];

	public function setCreateTimeAttr(){
		return time();
	}

	public function setLastLoginTimeAttr(){
		return time();
	}

	public function setLastLoginIpAttr(){
		return request()->ip();
	}


    public function getHeadimgAttr($value, $data)
    {
        if ($value && !preg_match('/^http(s)?:\\/\\/.+/', $value)) {
            return SITE_PATH . $value;
        } else {
            return $value;
        }
    }

    public function getCreateTimeAttr($value){
    	if ($value) {
            return date('Y-m-d', $value);
        } else {
            return $value;
        }
    }
}